<template>
	<view style="display: flex;justify-content: space-around;padding: 20rpx 0 50rpx;position: fixed;bottom: 0;left: 0;width: 100%;background-color: #fff;">
        <!-- 用户端 -->
		<view v-if="indecs==0" :class="kessy=='home'?'col':'col2'" class="ziti" @click="NavChange" data-cur="home">
			<view><image :src="kessy=='home'?'../../static/taber/index2.png':'../../static/taber/index.png'"></image></view>首页
		</view>
        <view v-if="indecs==0" :class="kessy=='questions'?'col':'col2'"  class="ziti" @click="NavChange" data-cur="questions">
        	<view><image :src="kessy=='questions'?'../../static/taber/wenda2.png':'../../static/taber/wenda.png'"></image></view>问答
        </view>
		<view v-if="indecs==0" :class="kessy=='subscribe'?'col':'col2'" class="ziti" @click="NavChange" data-cur="subscribe">
			<view><image :src="kessy=='subscribe'?'../../static/taber/shangc2.png':'../../static/taber/shangc.png'"></image></view>商城
		</view>

    <view v-if="indecs==0" :class="kessy=='test'?'col':'col2'"  class="ziti" @click="NavChange" data-cur="test">
      <view><image :src="kessy=='test'?'../../static/taber/gongyi2.png':'../../static/taber/gongyi.png'"></image></view>心里测题
    </view>

		<view v-if="indecs==0" :class="kessy=='publics'?'col':'col2'"  class="ziti" @click="NavChange" data-cur="publics">
			<view><image :src="kessy=='publics'?'../../static/taber/gongyi2.png':'../../static/taber/gongyi.png'"></image></view>公益救助
		</view>

       <view v-if="indecs==0" :class="kessy=='user1'?'col':'col2'"   class="ziti" @click="NavChange" data-cur="user1">
       	<view><image :src="kessy=='user1'?'../../static/taber/user2.png':'../../static/taber/user.png'"></image></view>我的
       </view>

       <!-- 咨询师端 -->

        <view v-if="indecs==1" :class="kessy=='workbench'?'col':'col2'" class="ziti" @click="NavChange" data-cur="workbench">
        	<view><image :src="kessy=='workbench'?'../../static/taber/index2.png':'../../static/taber/index.png'"></image></view>工作台
        </view>
        <view v-if="indecs==1" :class="kessy=='questions'?'col':'col2'"  class="ziti" @click="NavChange" data-cur="questions">
        	<view><image :src="kessy=='questions'?'../../static/taber/wenda2.png':'../../static/taber/wenda.png'"></image></view>问答
        </view>
        <view v-if="indecs==1" :class="kessy=='subscribe'?'col':'col2'" class="ziti" @click="NavChange" data-cur="subscribe">
        	<view><image :src="kessy=='subscribe'?'../../static/taber/shangc2.png':'../../static/taber/shangc.png'"></image></view>商城
        </view>
        <view v-if="indecs==1" :class="kessy=='orderForm'?'col':'col2'" class="ziti" @click="NavChange" data-cur="orderForm">
            <view><image :src="kessy=='orderForm'?'../../static/taber/oder2.png':'../../static/taber/oder.png'"></image></view>客戶管理
        </view>
      <!--  <view v-if="indecs==1" :class="kessy=='xxlb'?'col':'col2'" class="ziti" @click="NavChange" data-cur="xxlb">
        	<view><image :src="kessy=='xxlb'?'../../static/22.png':'../../static/21.png'"></image></view>消息列表
        </view> -->

        <view v-if="indecs==1" :class="kessy=='user'?'col':'col2'"   class="ziti" @click="NavChange" data-cur="user">
        	<view><image :src="kessy=='user'?'../../static/taber/user2.png':'../../static/taber/user.png'"></image></view>个人中心
        </view>

        <!-- 商城 -->
        <view v-if="indecs==2" :class="kessy=='stores'?'col':'col2'"   class="ziti" @click="NavChange" data-cur="stores">
        	<view><image :src="kessy=='stores'?'../../static/taber/soter2.png':'../../static/taber/soter.png'"></image></view>商城
        </view>
        <view v-if="indecs==2" :class="kessy=='classify'?'col':'col2'"   class="ziti" @click="NavChange" data-cur="classify">
        	<view><image :src="kessy=='classify'?'../../static/taber/fenlei2.png':'../../static/taber/fenlei.png'"></image></view>分类
        </view>
        <view v-if="indecs==2" :class="kessy=='pointsMall'?'col':'col2'"   class="ziti" @click="NavChange" data-cur="pointsMall">
        	<view><image :src="kessy=='pointsMall'?'../../static/taber/jifen2.png':'../../static/taber/jifen.png'"></image></view>积分商城
        </view>
        <view v-if="indecs==2" :class="kessy=='shoppingmall'?'col':'col2'"   class="ziti" @click="NavChange" data-cur="shoppingmall">
        	<view>
            <image :src="kessy=='shoppingmall'?'../../static/taber/gouwuc2.png':'../../static/taber/gouwuc.png'"></image>
            <span v-if="count > 0" class="count" v-text="count"></span>
          </view>购物车
        </view>
        <view v-if="indecs==2" :class="kessy=='shoppuser'?'col':'col2'"   class="ziti" @click="NavChange" data-cur="shoppuser">
        	<view><image :src="kessy=='shoppuser'?'../../static/taber/wde2.png':'../../static/taber/wode.png'"></image></view>我的
        </view>

	</view>
</template>

<script>
	import {cartList} from "../../api";
  import login from "../login/login";

  export default {
		props: ['kessy','indecs'],
		data() {
			return {
				show: false,
				PageCur: '',
				commponent1Key: 0,
				commponent2Key: 0,
        count: 0, // 购物车商品数
			}
		},
		onLoad() {
			//console.log("j进")
			//console.log(this.kessy)
			/* this.PageCur = 'home'
				++this.commponent1Key
				++this.commponent2Key */
		},
		created() {
		},
		methods: {
			NavChange: function(e) {
            let that=this
			 this.PageCur = e.currentTarget.dataset.cur
                if(this.PageCur=='subscribe'){
                    uni.showModal({
                        content: '切换商城',
                        success: function (res) {
                            if (res.confirm) {
                               that.$emit('childFn', that.PageCur);
                            } else if (res.cancel) {
                            }
                        }
                    })
                }
                else{
					console.log(that.PageCur)
                    that.$emit('childFn', that.PageCur);
                }

                this.queryShoppingNum()
			},

      queryShoppingNum() {
        this.count = 0
        cartList({pageNum: 1,pageSize: 30}).then(res => {
          if (res.rows.length > 0) {
            for(let i = 0; i < res.rows.length; i++){
              this.count = this.count*1 + res.rows[i].cartNum
            }
            console.log(this.count)
          }

        })
      }

		}
	}
</script>

<style lang="scss">
    .clo2{
        color: #9DABC0;
    }
    .col{
        color: #0A78CD;
    }
    .ziti{
        font-size: 20rpx;
        text-align: center;
        image{
            width: 50rpx;
            height: 50rpx;
        }
    }

    .count{
      padding: 0 8rpx;
      color: white;
      background: red;
      border-radius: 50%;
      position: absolute;
      left: 540rpx;
      bottom: 110rpx;
      opacity: 0.8;
    }

</style>
